<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/8/21 0021
 * Time: 下午 5:48
 */

namespace App\Http\Controllers\Xcx;


use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\News;

class KefuController extends Controller
{
    public function validate(Request $request)
    {
        $signature = $request->get('signature','');
        $timestamp = $request->get('timestamp','');
        $nonce = $request->get('nonce','');

        $token = 'yangjinlei';
        $tmpArr = array($token, $timestamp, $nonce);
        sort($tmpArr, SORT_STRING);
        $tmpStr = implode( $tmpArr );
        $tmpStr = sha1( $tmpStr );

        if( $tmpStr == $signature ){
            echo true;die;
        }else{
            echo false;die;
        }
    }
    public function news(Request $request)
    {

        $size = $request -> input('size',10);
        $page = $request -> input('page',1);
        $data = \DB::table('news')->select('id','title','created_at','cate','image')->limit($size)->offset(($page-1)*$size)->get();
        foreach ($data as $k=>$v){
            $v->created_at = date('Y.m.d',strtotime($v->created_at));
        }
        return $this->success($data);

    }
    public function newinfo(Request $request,$id)
    {
        $data = News::where('id',$id)->first();
        
        return $this->success($data);

    }
}